import React from "react";
import { Input, Icon /* , Select */ } from "antd";

const InputSearch = Input.Search;
// const { Option } = Select;

class QueryExtra extends React.Component {
  state = { searchName: "" };

  componentDidMount() {
    const { getRef } = this.props;
    if (getRef) getRef(this);
  }

  handleReset = () => {
    this.setState({ searchName: "" });
  };

  handleSearch = (value) => {
    const { onSearch } = this.props;
    // const { tenantId } = this.state;
    if (onSearch instanceof Function) onSearch({ searchName: value /* , tenantId */});
  };

  handleValueChange = (e) => {
    const inputValue = e.target.value;
    const { onChange } = this.props;
    // const { tenantId } = this.state;
    this.setState({ searchName: inputValue.trim() });
    if (onChange instanceof Function)
      onChange({ searchName: inputValue.trim()/* , tenantId */ });
  };

  /*
  handleSelectChange = (v) => {
    const { onChange, onSearch } = this.props;
    const { searchName } = this.state;
    this.setState({ tenantId: v });
    if (onChange instanceof Function) onChange({ tenantId: v, searchName });
    if (onSearch instanceof Function) onSearch({ tenantId: v, searchName });
  };
  */

  render() {
    const { visible, handleFilterVisible/* , tenantList */ } = this.props;
    const { searchName /* , tenantId */ } = this.state;
    return (
      <div>
        {/*
        <Select
          placeholder="请选择所属租户"
          onChange={this.handleSelectChange}
          value={tenantId}
          className="select__search"
          allowClear
        >
          {tenantList.map((selectItem) => (
            <Option value={selectItem.id} key={selectItem.id}>
              {selectItem.tenantName}
            </Option>
          ))}
        </Select>
        */}
        <InputSearch
          placeholder="请输入表单名称"
          onSearch={this.handleSearch}
          onChange={this.handleValueChange}
          value={searchName}
          className="input__search"
        />
        <span
          className={`a__link advanced__filter ${
            visible && "advanced__filter__up"
          }`}
        >
          <span onClick={handleFilterVisible} style={{ cursor: "pointer" }}>
            <span>{visible ? "收起" : "高级筛选"}</span>
            {visible ? <Icon type="up" /> : <Icon type="down" />}
          </span>
        </span>
      </div>
    );
  }
}
export default QueryExtra;
